﻿ <?php
require_once('calendar/classes/tc_calendar.php');
require_once('base.php');
header ( "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); 
 header ("Pragma: no-cache");
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 
 <head>
   <style type="text/css">
   A {
    color: #800000;
   }
   A:visited {
    color: #800000;
   }
   </style>
 <meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
 <title>OWA reports</title>
 <script src="http://code.jquery.com/jquery-latest.js"></script>
 <script language="javascript" src="jquery-1.6.4.js"></script>
 <script language="javascript" src="calendar/calendar.js"></script>

 <link href="calendar/calendar.css" rel="stylesheet" type="text/css">
 </head>
<body>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr><td>
<img src="ecom.bmp"><br><br>
<a href="oma.php">Перейти к отчетам OMA</a><br><br>
Выберите критерии сортировки. <br>Если ничего не выбирать - выводятся все значения.<br>
"-" означает отсутствие информации - пользователь не ввел login.<br>
<br>

</td>
</tr>
<tr>
<td>
	<form id="form1" name="date" method="post" action="owa.php"> 
	<p> 
	<table border="0" >
	<tr>
	<td>
	<select name="ip_list" " id="ip_list">
	<?php 
    //viborka po unikalnim IP - iz nih sostavlen vipadayushii spisok
	$mydb = new Database();
	$mydb->dbConnect();
	$table = "owa";
	$query="SELECT * FROM $table GROUP BY FromIP";
	$result=mysql_query($query);
	$num_fields = mysql_num_fields($result);
	
	echo "<option value= '' > Select IP </option>";
	while($row = mysql_fetch_array($result)) {
		echo "<option value='".$row['FromIP']."'>".$row['FromIP']."</option>";
	}
	echo "</select>";
	?>
	
<script language="javascript">

    $("#ip_list").change(function () {
    
          $("#login_list").attr('disabled','disabled');
		  $("#fullname_list").attr('disabled','disabled');
              });
</script>
	</td>
    <td>
	
	<?php
	//viborka po unikalnim loginam - iz nih sostavlen vipadayushii spisok
	$mydb = new Database();
	$mydb->dbConnect();
	$table = "owa";
	$query="SELECT * FROM $table GROUP BY Login";
	$result=mysql_query($query);
	$num_fields = mysql_num_fields($result);

	echo "<select name='login_list' id='login_list'>";
	echo "<option value= '' > Select Login </option>";
	while($row = mysql_fetch_array($result)) {
		echo "<option value='".$row['Login']."'>".$row['Login']."</option>";
	}
	echo "</select>";
	?>
	</td>
	<script language="javascript">

    $("#login_list").change(function () {
    
          $("#ip_list").attr('disabled','disabled');
		  $("#fullname_list").attr('disabled','disabled');
              });
</script>
	<td>
	<?php
	//viborka po unikalnim loginam - iz nih sostavlen vipadayushii spisok
	$mydb = new Database();
	$mydb->dbConnect();
	$table = "owa";
	$query="SELECT * FROM ".$table." GROUP BY FullName";
	$result=mysql_query($query);
	$num_fields = mysql_num_fields($result);

	echo "<select name='fullname_list' id='fullname_list'>";
	echo "<option value= '' > Select FullName </option>";
	while($row = mysql_fetch_array($result)) {
		echo "<option value='".$row['FullName']."'>".$row['FullName']."</option>";
	}
	echo "</select>";
	?>
	</td>

<script language="javascript">
$("#fullname_list").change(function () {
    
          $("#login_list").attr('disabled','disabled');
		  $("#ip_list").attr('disabled','disabled');
              });
</script>

	<td width="200px">
	<?php					
     $date3_default = "2011-09-1";
     $date4_default = "2012-10-30";

	  $myCalendar = new tc_calendar("date3", true, false);
	  $myCalendar->setIcon("calendar/images/iconCalendar.gif");
	  $myCalendar->setDate(date('d', strtotime($date3_default))
            , date('m', strtotime($date3_default))
            , date('Y', strtotime($date3_default)));
	  $myCalendar->setPath("calendar/");
	  $myCalendar->setYearInterval(1970, 2020);
	  $myCalendar->setAlignment('left', 'bottom');
	  $myCalendar->setDatePair('date3', 'date4', $date4_default);
	  $myCalendar->writeScript();	  
	  
	  $myCalendar = new tc_calendar("date4", true, false);
	  $myCalendar->setIcon("calendar/images/iconCalendar.gif");
	  $myCalendar->setDate(date('d', strtotime($date4_default))
           , date('m', strtotime($date4_default))
           , date('Y', strtotime($date4_default)));
	  $myCalendar->setPath("calendar/");
	  $myCalendar->setYearInterval(2011, 2020);
	  $myCalendar->setAlignment('left', 'bottom');
	  $myCalendar->setDatePair('date3', 'date4', $date3_default);
	  $myCalendar->writeScript();	  

 ?>
	</td><td>
	<input type="submit" name="(javascript:this.form.date3.value)" value="Show it!" />
	<input name="javascript:this.form.date4.value)" type="hidden" value="javascript:this.form.date4.value">
	</td></tr></table>
	 
	<?php
	$mydb = new Database();
	$mydb->dbConnect();
 
	$table = "owa";
	//$query="SELECT * FROM owa";
	//po umolchaniyu pokajem vse, chto est
	//$result=mysql_query($query);
	$num_fields = mysql_num_fields(mysql_query($query));


	//dannie iz formi , data nije
	$selected_ip = $_POST["ip_list"];
	$selected_login = $_POST["login_list"];
	$selected_fullname =$_POST["fullname_list"];
	$selected_date1=$_POST["date3"];
	$selected_date2=$_POST["date4"];


	$query="SELECT * FROM `".$table."` WHERE DATE BETWEEN '".$selected_date1."' AND '".$selected_date2."' AND Login LIKE '%".$selected_login."%' AND FromIP LIKE '%".$selected_ip."%' AND FullName LIKE '%".$selected_fullname."%'";
	//echo $query;


	echo "<br><b>Выбранный IP: ".$selected_ip."</b><br>";
	echo "<b>Выбранный Login: ".$selected_login."</b><br>";
	echo "<b>Выбранное имя пользователя: ".$selected_fullname."</b><br>";
	echo "<b>Выбранная дата: ".$selected_date1."  -  ".$selected_date2."</b><br>";

	echo '<table border="1" cellspacing="0" cellpadding="0"><tr>'.'<td width = "200px">Date</td>'.'<td width = "200px">Time</td>'.'<td width = "200px">IP</td>'.'<td width = "200px">Login</td>'.'<td width = "200px">Domain</td>'.'<td width = "400px">FullName</td>'.'<td width = "200px">Client</td>'.'<td width = "200px">Status</td>'.'</tr>';

	$result=mysql_query($query);
	$num_fields = mysql_num_fields($result);

	for($i = 0; $i < $num_fields; $i++){
		while ($row=mysql_fetch_array($result)) {
		if ($row[7]=="200" || $row[7]==207) {
		$row[7]="Sucssess";
		$color="#90EE90";
		}
		if ($row[7]=="401") {
		$row[7]="Unsuccess";
		$color="#FA8072";		
		}	
		echo '<tr bgcolor="'.$color.'">'.'<td width = "200px" align="left">'.$row[0].'</td>'.'<td width = "200px" align="left">'.$row[1].'</td>'.'<td width = "200px" align="left">'.$row[2].'</td>'.'<td width = "200px" align="left">'.$row[3].'</td>'.'<td width = "200px" align="left">'.$row[4].'</td>'.'<td width = "400px" align="left">'.$row[5].'</td>'.'<td width = "200px" align="left">'.$row[6].'</td>'.'<td width = "200px" align="left">'.$row[7].'</td>'.'</tr>'; 
		}
	}
	echo '</table>';
	?>

	</p>
	</form>
 
 </td></tr>
 </table>
 </body>
 </html>
 
 
 

